private String uriAPI = "PHP位置";
private String sendPostDataToInternet(String s1 ,String s2 , String s3 , String s4 , String s5){
HttpPost httpRequest = new HttpPost(uriAPI);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", s1));
params.add(new BasicNameValuePair("password", s2));
params.add(new BasicNameValuePair("name", s3));
params.add(new BasicNameValuePair("school", s4));
params.add(new BasicNameValuePair("job", s5));
try {
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
String strResult = EntityUtils.toString(httpResponse.getEntity());
return strResult;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
class sendPostRunnable implements Runnable
{
String s1 = null;
String s2 = null;
String s3 = null;
String s4 = null;
String s5 = null;
public sendPostRunnable(String s1 ,String s2 , String s3 , String s4 , String s5){
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
this.s4 = s4;
this.s5 = s5;
}
@Override
public void run() {
String result = sendPostDataToInternet(s1,s2,s3,s4,s5);
mHandler.obtainMessage(REFRESH_DATA, result).sendToTarget();
}
}